/**
 * Created by user on 2018/11/14.
 */
'use strict'
const lodash = require('lodash')

const { cloneDeep } = lodash
const L = (code, msg) => {
    return { code, msg }
}

const ajaxCode = {
    SUCCESS: L(200, '成功'),
    EXCEPT_ERROR: L(-201, '系统错误'),
    SQL_ERROR: L(-301, '系统错误'),
    NO_DATA_ERROR: L(-401, '未查询数据'),
    OTHER_ERROR: L(-501, '系统错误'),
    PARAMS_ERROR: L(-601, '参数错误'),
}

const sleepPromise = (t = 1.5) => {
    return new Promise(resolve => {
        setTimeout(() => {
            resolve()
        }, t * 1000)
    })
}





module.exports = {
    ajaxReturn(data = null, error = { code: ajaxCode.SUCCESS.code, msg: ajaxCode.SUCCESS.msg }) {
        return { ...error, data }
    },
    ajaxCode,
    cloneDeep,
    sleepPromise
}